package com.eds.controller;

import com.eds.dto.CourseReviewDTO;
import com.eds.pojo.BaseResult;
import com.eds.pojo.CodeEnum;
import com.eds.service.CourseReviewService;
import com.pojo.CourseReview;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 *
 * @ClassName：CourseReviewController
 * @Author: vvSmile
 * @Date: 2025/04/06
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
@RestController
@RequestMapping("/courseReviewController")
public class CourseReviewController {

    @Autowired
    private CourseReviewService courseReviewService;

    //增加评论
    @PostMapping("/insertCourseReview")
    public BaseResult insertCourseReview(@RequestHeader("authorization") String token, @RequestBody CourseReview courseReview) {
        BaseResult insertCourseReviewReturn = courseReviewService.insertCourseReview(token, courseReview);
        return insertCourseReviewReturn;

    }

    //回复
    @PostMapping("/replyCourseReview")
    public BaseResult replyCourseReview(@RequestHeader("authorization") String token, @RequestBody CourseReview courseReview) {
        BaseResult replyCourseReviewReturn = courseReviewService.replyCourseReview(token, courseReview);
        return replyCourseReviewReturn;
    }

    //删除评论
    @DeleteMapping("/deleteCourseReview")
    public BaseResult deleteCourseReview(@RequestHeader("authorization") String token, @RequestParam("reviewId") Long reviewId) {
        boolean deleteCourseReviewReturn = courseReviewService.deleteCourseReview(token, reviewId);
        if (deleteCourseReviewReturn) {
            return BaseResult.ok("删除成功！");
        } else {
            return BaseResult.error(CodeEnum.DELETE_COURSE_REVIEW_ERROR);
        }
    }


    //获取一个课程的回复列表
    @GetMapping("/getCourseReviewList")
    public BaseResult getCourseReviewList(@RequestParam("courseId") Long courseId) {
        ArrayList<CourseReviewDTO> getCourseReviewReturn = courseReviewService.getCourseReviewList(courseId);
        if (getCourseReviewReturn != null) {
            return BaseResult.ok("获取课程的回复列表成功！", getCourseReviewReturn);
        } else {
            return BaseResult.error(CodeEnum.GET_COURSE_REVIEW_LIST_ERROR);
        }
    }


    //获取一个评论的回复列表
    @GetMapping("/getCourseReviewReplyList")
    public BaseResult getCourseReviewReplyList(@RequestParam("reviewId") Long reviewId) {
        ArrayList<CourseReviewDTO> getCourseReviewReplyListReturn = courseReviewService.getCourseReviewReplyList(reviewId);
        if (getCourseReviewReplyListReturn != null) {
            return BaseResult.ok("获取评论的回复列表成功！", getCourseReviewReplyListReturn);
        } else {
            return BaseResult.error(CodeEnum.GET_COURSE_REVIEW_REPLY_LIST_ERROR);
        }
    }

}
